package org.vectrics.common.controller;

import org.apache.log4j.*;
import java.io.*;


public class StaticPageBuilder {
    private static Category log = Category.getInstance(StaticPageBuilder.class);
    
    
    public boolean makePage(String content, String path, String fileName) {
        boolean result = false;
        if (verifyDirectory(path)) {
            try {
                // Save database to file
                String filePath = path + "/" + fileName;
                log.info("Writing configuration data to file: " + filePath);
                File htmlFile = new File(filePath);

                FileWriter writer = new FileWriter(htmlFile);

                writer.write(content);
                writer.close();
                result = true;

            }
            catch (java.io.IOException ioex) {
                log.error("Error writing schedule data to file", ioex);
            };
            
        }
        else {
            log.error("makePage() - error creating page, could not create directory: " + path);
        }
        return(result);
    }

    private boolean verifyDirectory(String path) {
        boolean created = false;
        File dir = new File(path);
        try {
            dir.mkdirs();
            created = true;
        }
        catch (Exception ex) {
            //Ignore exception
            log.error("Error creating directory: " + ex.getMessage());
        };
        return(created);
    };
    
    

}
